package com.lanyun.carworld.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lanyun.carworld.context.BaseContext;
import com.lanyun.carworld.model.entity.UserRole;
import com.lanyun.carworld.service.UserRoleService;

import javax.annotation.Resource;

public class RoleUtils {

    @Resource
    private UserRoleService userRoleService;

    //查询用户权限等级
    public int getRoleLevel() {
        Long userId = BaseContext.getCurrentId();

        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);

        UserRole userRole = userRoleService.getOne(queryWrapper);

        if (userRole == null) {
            return -1;
        }
        return userRole.getJurisdiction();
    }
}
